package com.crm.action;

import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;

import com.crm.pojo.User;
import com.crm.service.UserService;
import com.opensymphony.xwork2.ActionSupport;

public class AppAction extends ActionSupport implements SessionAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Map<String, Object> session;
	private User user;
	private UserService userService;
	
	@Action("index")
	public String index() {
		return SUCCESS;
	}
	
	@Action(value="login",results={
			@Result(name=LOGIN,type="redirectAction",params={"actionName","index","code","10000"}),
			@Result(name=SUCCESS,type="redirectAction",params={"actionName","list","namespace","/account"})
			}
		)
	public String login(){
		User u=userService.login(user);
		if(u!=null){
			session.put("user", u);
			return SUCCESS;
		}else{
			return LOGIN;
		}
	}
	
	
	/*
	 * set  get
	 * (non-Javadoc)
	 * @see org.apache.struts2.interceptor.SessionAware#setSession(java.util.Map)
	 */
	
	
	
	public void setSession(Map<String, Object> session) {
		// TODO Auto-generated method stub
		this.session=session;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Autowired
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	
}
